package form.element;

public class Checkbox extends Input
{
	public Checkbox(String name)
	{
		super(name, "checkbox");
	}

	@Override
	public String getCode()
	{
		if (isChecked())
		{
			setAttribute("checked", "checked");
		}
		else
		{
			removeAttribute("checked");
		}
		
		return super.getCode();
	}
	
	public boolean isChecked()
	{
		return value != null; 
	}
	
	@Override
	protected void prepareValue()
	{
		if (value != null)
		{
			setAttribute("value", true);
		}
	}
}
